/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgNotice
    {
        private readonly Dictionary<int, CfgNotice> _dataMap;
        private readonly List<CfgNotice> _dataList;


        public TbCfgNotice(ByteBuf _buf)
        {
            //first read common data
            _TbCommonNotice _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonNotice(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgNotice>(size * 3 / 2);
            _dataList = new List<CfgNotice>(size);

            for (int i = 0; i < size; i++)
            {
                CfgNotice _v;
                _v = CfgNotice.DeserializeCfgNotice(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgNotice> DataMap => _dataMap;
        public IReadOnlyList<CfgNotice> DataList => _dataList;

        public CfgNotice Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgNotice] config not found,id:" + key.ToString());

            return null;
        }

        public CfgNotice GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "notice";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgNotice LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgNotice(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgNotice
    {
        private CfgNotice(ByteBuf _buf, _TbCommonNotice _commonData)
        {
            Id = _buf.ReadInt();
            Type = (NoticeType)(_buf.ReadInt());
            Title = TableCenter.GetI18NText(_buf.ReadInt());
            Describe = TableCenter.GetI18NText(_buf.ReadInt());
            Subtext = TableCenter.GetI18NText(_buf.ReadInt());
            IsChangeColor = _buf.ReadBool();
            IsShowHavingNum = _buf.ReadBool();
            AutoChoose = _buf.ReadInt();
            AutoChooseTime = _buf.ReadInt();
            CanBeIgnored = _buf.ReadBool();
            ButtonText1 = TableCenter.GetI18NText(_buf.ReadInt());
            ButtonText2 = TableCenter.GetI18NText(_buf.ReadInt());
            IsShowClose = _buf.ReadBool();

            PostInit();
        }

        internal static CfgNotice DeserializeCfgNotice(ByteBuf _buf, _TbCommonNotice _commonData)
        {
            return new CfgNotice(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 提示类型
        /// </summary>
        public NoticeType Type { get; private set; }
        /// <summary>
        /// 标题栏名称
        /// </summary>
        public string Title { get; private set; }
        /// <summary>
        /// 信息文本
        /// </summary>
        public string Describe { get; private set; }
        /// <summary>
        /// 子文本-不支持参数（特殊处理的额外描述信息）
        /// </summary>
        public string Subtext { get; private set; }
        /// <summary>
        /// 持有道具低于展示数量时，是否改变颜色（0：不改变 1：改变）用于提示类型7、8的弹窗
        /// </summary>
        public bool IsChangeColor { get; private set; }
        /// <summary>
        /// 是否显示持有数量（0：隐藏 1：显示）用于提示类型7、8的弹窗
        /// </summary>
        public bool IsShowHavingNum { get; private set; }
        /// <summary>
        /// 自动选择操作（0无自动选择，1自动选择按钮1，2自动选择按钮2）
        /// </summary>
        public int AutoChoose { get; private set; }
        /// <summary>
        /// 多久后自动选择（秒）
        /// </summary>
        public int AutoChooseTime { get; private set; }
        /// <summary>
        /// 可否选择本次登陆不再提示
        /// </summary>
        public bool CanBeIgnored { get; private set; }
        /// <summary>
        /// 按钮1文本
        /// </summary>
        public string ButtonText1 { get; private set; }
        /// <summary>
        /// 按钮1文本
        /// </summary>
        public string ButtonText2 { get; private set; }
        /// <summary>
        /// 显示关闭按钮
        /// </summary>
        public bool IsShowClose { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonNotice
    {

        internal _TbCommonNotice(ByteBuf _buf)
        {
        }

    }
}
